package com.turing.post.tuxedo.util;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.jdom2.Element;

import com.turing.post.util.PCPSApplicationException;

/**
 * 支付交易销售单信息
 * 
 * @author yxb
 * 
 */
@SuppressWarnings("serial")
public class SaleOrderObj implements Serializable {
	/**
	 * 商户销售单号(可选)
	 */
	public String saleOrderNo = null;

	/**
	 * 销售单细目条数
	 */
	public BigInteger businessDetailNum = BigInteger.ZERO;

	/**
	 * 产品明细
	 */
	public ArrayList<BusinessDetailObj> businessDetailObjs = new ArrayList<BusinessDetailObj>();

	/**
	 * 解析售货单信息
	 * 
	 * @param node
	 * @throws Exception
	 */
	public void parseSaleOrderObj(Element node) throws PCPSApplicationException {
		// 销售单号
		saleOrderNo = TransXmlHelper.getOptionalString(node,
				TransXmlHelper.XML_NODE_SaleOrderNo);
		// 商品细目条数
		businessDetailNum = TransXmlHelper.getInteger(node,
				TransXmlHelper.XML_NODE_BusinessDetailNum);

		// 产品明细
		List<Element> prodels = node
				.getChildren(TransXmlHelper.XML_NODE_BusinessDetail);
		if (businessDetailNum.intValue() > 0
				&& (prodels == null || prodels.size() != businessDetailNum
						.intValue()))
			ParaseException.TransParamException("prodDetail conflict!");

		BusinessDetailObj pd = null;

		for (Element el : prodels) {
			pd = new BusinessDetailObj();
			pd.parseProdDetailObj(el);
			businessDetailObjs.add(pd);
		}
	}

}
